<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <link rel="icon" type="image/png" href="../img/icon.png">
    <link rel="stylesheet" href="../css/toastr.min.css">
    <link rel="stylesheet" href="../css/all.css">
    <style>
    </style>
</head>
<body>
<div id="app" v-cloak>
    <form id="loginForm" class="center-form">
        <div class="form-item">
            <label class="form-label">登录名:</label>
            <input class="form-input" type="text" name="loginName" v-model="loginName">
        </div>
        <div class="form-item">
            <label class="form-label">密码:</label>
            <input class="form-input" type="password" name="pwd" v-model="pwd">
        </div>
        <div class="form-item text-center">
            <button type="button" class="btn" @click="doReset" >重&nbsp;置</button>
            <button type="button" class="btn btn-primary" @click="doLogin($event)" >登&nbsp;录</button>
        </div>
        <hr>
        <div>
            <a href="./register.html">没有账户，去注册</a>
        </div>
    </form>
</div>
<script src="../js/vue.min.js" ></script>
<script src="../js/jquery-3.3.1.min.js" ></script>
<script src="../js/toastr.min.js" ></script>
<script src="../js/base.js" ></script>
<script>
    //Vue.config.devtools = true; // 描述浏览器调试工具是否可用
    new Vue({
        el: "#app",
        data: {
            loginName: "",
            pwd: ""
        },
        methods: {
            doReset() {
                this.loginName = "";
                this.pwd = "";
            },
            doLogin(e) {
                //console.log(this.loginName, this.pwd);
                $.ajax({
                    type: 'post',
                    url: baseUrl + "/front/stu/login",
                    data: {
                        loginName: this.loginName,
                        pwd: this.pwd
                    },
                    dataType: 'json',
                    success: (result) => {
                        toastr[result.success ? "success":"warning"](result.msg);
                        if(result.success) {
                            localStorage.setItem("stuLogin", JSON.stringify(result.data));
                            setTimeout(()=>{
                                location.href = baseUrl + "/stu/stu_center.html";
                            }, 500);
                            return;
                        }
                    },
                    error: (xhr) => {
                        toastr.error('网络异常');
                    }
                });
            }
        }
    });
</script>
</body>
</html>